<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

    <!-- 
        定义和用法：
        closed属性可返回一个布尔值，该值声明了窗口是否已经关闭
        语法：window.closed
     -->
    <button onclick="openWin()">打开窗口</button>
    <button onclick="closeWin()">关闭窗口</button>
    <button onclick="checkWin()">判断窗口是否打开</button>
    <p id="msg">这里</p>

    <script>
        var myWindon;

        function openWin() {
            myWindon = window.open("http://www.baidu.com", "", "width:200;height:200;")
        }

        function closeWin() {
            if (myWindon) {
                myWindon.close();
            }
        }
        

        function checkWin() {
            if(!myWindon){
                document.getElementById("msg").innerHTML="这个页面并没有被打开过";
            }else if(myWindon.closed){
                document.getElementById("msg").innerHTML="这个窗口被关闭了";
            }else{
                document.getElementById("msg").innerHTML="这个窗口还没有被关闭了";
            }
          }
    </script>
</body>

</html>